from alibabacloud_tea_openapi.models import Config
from alibabacloud_xrengine20230313.client import Client
from alibabacloud_xrengine20230313.models \
  import LoginModelScopeRequest, ListCommonMaterialsRequest, ListMotionShopTasksRequest, GenerateMotionShopVideoUploadUrlRequest, \
         MotionShopVideoDetectRequest, QueryMotionShopVideoDetectResultRequest, SubmitMotionShopTaskRequest, BatchQueryMotionShopTaskStatusRequest
from config.env import access_key_id, access_key_secret, api_endpoint

config = Config(access_key_id=access_key_id, access_key_secret=access_key_secret, endpoint=api_endpoint)
xr_client = Client(config=config)

def login(user_id):
  return xr_client.login_model_scope(LoginModelScopeRequest(token=user_id, type='MODEL_SCOPE')).to_map()
  

def list_common_materials():
  response = xr_client.list_common_materials(ListCommonMaterialsRequest(type='MOTION_SHOP_AVATAR')).to_map()
  print('[list_common_materials]response:', response)
  return response['body']

def list_motion_shop_tasks(jwt, current, size):
  response = xr_client.list_motion_shop_tasks(ListMotionShopTasksRequest(jwt_token=jwt, current=current, size=size)).to_map()
  print('[list_motion_shop_tasks]response: ', response)
  return response['body']

def generate_motion_shop_video_upload_url(jwt):
  response = xr_client.generate_motion_shop_video_upload_url(GenerateMotionShopVideoUploadUrlRequest(jwt_token=jwt)).to_map()
  print('[generate_motion_shop_video_upload_url]response:', response)
  return response['body']

def motion_shop_video_detect(jwt, oss_key):
  response = xr_client.motion_shop_video_detect(MotionShopVideoDetectRequest(jwt_token=jwt, oss_key=oss_key)).to_map()
  print('[motion_shop_video_detect]response:', response)
  return response['body']

def query_motion_shop_video_detect_result(jwt, jobId):
  response = xr_client.query_motion_shop_video_detect_result(QueryMotionShopVideoDetectResultRequest(jwt_token=jwt, job_id=jobId)).to_map()
  print('[query_motion_shop_video_detect_result]response:', response)
  return response['body']

def submit_motion_shop_task(jwt, title, videoId, avatarId):
  response = xr_client.submit_motion_shop_task(SubmitMotionShopTaskRequest(jwt_token=jwt, title=title, video_id=videoId, avatar_id=avatarId)).to_map()
  print('[submit_motion_shop_task]response:', response)
  return response['body']

def batch_query_motion_shop_task_status(jwt, taskIds):
  taskIds = ','.join(taskIds)
  response = xr_client.batch_query_motion_shop_task_status(BatchQueryMotionShopTaskStatusRequest(jwt_token=jwt, task_id=taskIds)).to_map()
  print('[batch_query_motion_shop_task_status]response:', response)
  return response['body']